package com.aal.model;

import com.aal.entity.Product;
import java.util.List;

/**
 *
 * @author Hoang
 */
public class Category {

    private CategoryManagement cm = new CategoryManagement();
    private ProductManagement pm = new ProductManagement();
    
    /**
     * get list of category available in database
     *
     * @return the value of categoryList
     */
    public List<com.aal.entity.Category> getCategoryList() {
        return cm.getViewAll();
    }

    private int categoryID = 1;

    /**
     * Set the value of categoryID for getCategory() to work
     *
     * @param categoryID new value of categoryID
     */
    public void setCategoryID(int categoryID) {
        this.categoryID = categoryID;
    }
    
    /**
     * Get the category entity based on category ID previously set
     *
     * @return the value of category
     */
    public com.aal.entity.Category getCategory() {
        cm.setCategoryID(categoryID);
        return cm.getCategory();
    }

    private List<Product> productList;

    /**
     * Get list of products in category with ID set at setCategoryID
     *
     * @return the value of productList
     */
    public List<Product> getProductList() {
        productList = pm.setSearchproductbycategory(categoryID);
        return productList;
    }

    private int productPages;

    /**
     * Get the number of pages of products in current category, based on basic
     * of 15 product per page
     *
     * @return the value of productPages
     */
    public int getProductPages() {
        getProductList();
        if (productList == null) return 0;
        productPages = productList.size() / 10;
        if (productList.size() % 10 != 0) productPages++;
        return productPages;
    }
}
